package com.thingsgrid.device.utils;

import com.alibaba.fastjson.JSONArray;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 功能说明：JSON转换
 *
 * @author 李龙飞
 * @since 2019/9/5 19:42
 */
public class JsonTransform {

	/**
	 *说明：设备控制指令下发
	 *@author lilongfei
	 *@since 2019/9/5 19:46
	 */
	public static String deviceControlJsonTransform(String action,String code,String sig,String token,String fsn){
		Map<String,Object> bodyMap = new HashMap<>();
		bodyMap.put("method","device-control");
		bodyMap.put("requestid", UUID.randomUUID().toString());
		bodyMap.put("action",action);
		bodyMap.put("timestamp",System.currentTimeMillis());
		bodyMap.put("code",code);
		bodyMap.put("sig",sig);
		String bodyJSON = JSONArray.toJSONString(bodyMap);
		Map<String,Object> controlMap = new HashMap<>();
		controlMap.put("token",token);
		controlMap.put("fsn",fsn);
		controlMap.put("body",bodyJSON);
		return JSONArray.toJSONString(controlMap);
	}

}
